
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/vfs.h>
#include <netinet/in.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <errno.h>

#include <librally.h>

#ifndef _RSTATD
#define _RSTATD

typedef struct Worker {
	rp_pid_t pid;
	int exitFlag;
	Score *score;
	struct Worker *next;
	struct Worker *prev;
} Worker;

typedef struct {
	int total;
	int idle;
	Worker *head;
	Worker *tail;
} Scoreboard;

typedef struct {
	char filename[MAX_FILENAME_LENGTH];
	unsigned long filesize;
} File;

typedef struct {
	int size;
	int free;
	File *files;
} Fvector;

typedef struct Info {
	/*--- Sys ---*/
	char os[MAX_LINE_LENGTH];
	char arch[MAX_LINE_LENGTH];
	/*--- network ---*/
	char hostname[MAX_HOSTNAME_LENGTH];
	char ip[64];
	int port;
	/*--- cpu ---*/
	int ncpu;
	/*--- mem ---*/
	int mem_max;
	int mem_free;
	/*--- disk ---*/
	unsigned long disk_max;
	unsigned long disk_free;
	/*--- load ---*/
	/*--- file ---*/
	Fvector *fv;
	/*---Score---*/
	Scoreboard sb_info;
} Info;

typedef struct {
	int cfgc;
	KeyValue *cfgv;
	char *logdir;
	Log_Level loglv;
	int num_child_prefork;
	int num_child_min;
	int num_child_idle;
	struct timeval tv_heartbeat;
	char *rpdir;
	char *hostname_rindexd;
	struct sockaddr_in addr_rindexd;
} Config;

typedef struct {
	OpCode code;
	int fd_rindexd;
	int fd_pod[2];
	Scoreboard sb_live;
	Scoreboard sb_dead;
	Info info;
	struct event_base *evb_server;
	struct event ev_hb;
	struct event ev_adm;
} Global;

typedef struct {
	char *bindir;
	char *cfgdir;
} Env;

Config config;
Global global;
Env env;

#endif 	// _RSTATD

